from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
    # username删去的原因是AbstractUser类自带username
    # username = models.CharField(max_length=255, blank=True, null=True)
    # 密码长度设为255，因为AbstractUser会自动对密码进行加密，长度远大于原先设置
    id = models.AutoField(primary_key=True, null=False)
    password = models.CharField(max_length=255, blank=True, null=True)
    email = models.CharField(max_length=255, blank=True, null=True)
    # 0为否，1为是
    scholar = models.IntegerField(default=False, blank=True, null=True)
    admin = models.IntegerField(blank=True, null=True)
    realname = models.CharField(max_length=255, blank=True, null=True)
    sex = models.CharField(max_length=255, blank=True, null=True)
    nation = models.CharField(max_length=255, blank=True, null=True)
    sign = models.CharField(max_length=255, blank=True, null=True)
    field = models.CharField(default="", max_length=255, blank=True, null=True)
    image_url = models.CharField(default="https://obs-0dcd.obs.cn-north-4.myhuaweicloud.com/默认头像.png",max_length=255, blank=True, null=True)
    isNoteCommentable = models.BooleanField(default=True, blank=True, null=True)
    isNoteVisible = models.BooleanField(default=True, blank=True, null=True)
    isLiteratureCommentable = models.BooleanField(default=True, blank=True, null=True)
    isCollectionVisible = models.BooleanField(default=True, blank=True, null=True)
    color = models.CharField(default="白色", max_length=255, blank=True, null=True)
    language = models.CharField(default="中文", max_length=255, blank=True, null=True)
    aid = models.CharField(default="", max_length=255, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'user'


class Collection(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    pid = models.CharField(max_length=255, blank=True, null=True)
    nid = models.ForeignKey('Note', models.CASCADE, db_column='nid', blank=True, null=True, related_name='note_id')
    uid = models.ForeignKey('User', models.CASCADE, db_column='uid', blank=True, null=True)
    visible_type = models.IntegerField(default=False, blank=True, null=True)
    time = models.DateField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'collection'


class Comment(models.Model):
    id = models.AutoField(primary_key=True,null=False)
    pid = models.CharField(max_length=255, blank=True, null=True)
    nid = models.ForeignKey('Note', models.CASCADE, db_column='nid', blank=True, null=True)
    # 0表示发送者，1表示回复者
    uid_0 = models.ForeignKey('User', models.CASCADE, db_column='uid_0', blank=True, null=True,
                              related_name="sender")
    uid_1 = models.ForeignKey('User', models.CASCADE, db_column='uid_1', blank=True, null=True,
                              related_name="answerer")
    visible_type = models.IntegerField(blank=True, null=True)
    content = models.TextField(blank=True, null=True)
    # -1表示发送型评论，1表示回复型评论
    response_id = models.IntegerField(blank=True, null=True)
    type = models.IntegerField(blank=True, null=True)
    like_number = models.IntegerField(default=0, blank=True, null=True)
    is_reported = models.BooleanField(default=False, blank=True, null=True)
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'comment'


class Message(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    date = models.DateTimeField(blank=True, null=True)
    content = models.TextField(blank=True, null=True)
    uid = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'message'


class Note(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    pid = models.CharField(max_length=255, blank=True, null=True)
    uid = models.ForeignKey('User', models.CASCADE, db_column='uid', blank=True, null=True)
    visible_type = models.IntegerField(default=False, blank=True, null=True)
    content = models.TextField(blank=True, null=True)
    introduction = models.TextField(blank=True, null=True)
    like_number = models.IntegerField(default=0, blank=True, null=True)
    image_url = models.CharField(max_length=128, blank=True, null=True)
    comment_number = models.IntegerField(default=0, blank=True, null=True)
    collection_number = models.IntegerField(default=0, blank=True, null=True)
    is_reported = models.BooleanField(default=False, blank=True, null=True)
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'note'


class Verificationcode(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    content = models.CharField(max_length=32, blank=True, null=True)
    date = models.DateTimeField(blank=True, null=True)
    type = models.IntegerField(blank=True, null=True)
    uid = models.ForeignKey(User, models.DO_NOTHING, db_column='uid', blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'verificationcode'


class Complain(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    pid = models.CharField(max_length=255, blank=True, null=True)
    introduction = models.CharField(max_length=255, blank=True, null=True)
    image_url = models.CharField(max_length=255, blank=True, null=True)
    # 联系方式
    contact = models.CharField(max_length=255, blank=True, null=True)
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'complain'


class Email(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    email = models.CharField(max_length=64, blank=True, null=True)
    time = models.DateTimeField(blank=True, null=True)
    type = models.IntegerField(blank=True, null=True)
    code = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'email'


class Like(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    cid = models.ForeignKey('Comment', models.CASCADE, db_column='cid', blank=True, null=True,
                            related_name='like_commment_id')
    nid = models.ForeignKey('Note', models.CASCADE, db_column='nid', blank=True, null=True,
                            related_name='like_note_id')
    uid = models.ForeignKey('User', models.CASCADE, db_column='uid', blank=True, null=True)
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'like'


class Missingpaper(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    uid = models.ForeignKey('User', models.CASCADE, db_column='uid', blank=True, null=True)
    title = models.CharField(max_length=128, blank=True, null=True)
    author = models.CharField(max_length=128, blank=True, null=True)
    keyword = models.CharField(max_length=128, blank=True, null=True)
    date = models.DateTimeField(blank=True, null=True)
    doi = models.CharField(max_length=128, blank=True, null=True)
    abstract = models.CharField(max_length=1024, blank=True, null=True)
    link = models.CharField(max_length=256, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'missingpaper'

class Subscribe(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    uid_0 = models.ForeignKey('User', models.CASCADE, db_column='uid_0', blank=True, null=True,related_name="subscriber")
    uid_1 = models.ForeignKey('User', models.CASCADE, db_column='uid_1', blank=True, null=True,related_name="subscribeder")
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'subscribe'

class Claim(models.Model):
    id = models.AutoField(primary_key=True, null=False)
    uid = models.CharField(default="", max_length=255, blank=True, null=True)
    aid = models.CharField(default="", max_length=255, blank=True, null=True)
    image_url = models.CharField(max_length=128, blank=True, null=True)
    text = models.TextField(blank=True, null=True)
    time = models.DateTimeField(blank=True, null=True,auto_now_add=True)

    class Meta:
        managed = True
        db_table = 'claim'